/*******************************************************************************
GThread.h

	Author:		LiuDingXi
	e-mail:		liudx@gmail.com
	Date time:	2010-06-07

	Copyright (C) 2010
	All rights reserved.
	
*******************************************************************************/
#ifndef _GTHREAD_H_
#define _GTHREAD_H_

#if (_OS_ == _OS_WINNT_) || (_OS_ == _OS_IPHONE_)

#include "pthread.h"
#include "semaphore.h"

#endif

class GLock
{
public:
	GLock();
	~GLock();

	BOOL	Create();
	BOOL	Destroy();

	BOOL	Lock();
	BOOL	Unlock();

protected:

#if (_OS_ == _OS_WINNT_) || (_OS_ == _OS_IPHONE_)

	pthread_mutex_t	m_mutex;

#endif

};

class GSemaphore
{
public:
	GSemaphore();
	~GSemaphore();

	BOOL	Create(LPCTSTR szName);
	BOOL	Destroy(LPCTSTR szName);

	SINT	Wait();
	SINT	Signal();

protected:

#if (_OS_ == _OS_WINNT_)

	sem_t	m_sem;

#endif

#if (_OS_ == _OS_IPHONE_)

	sem_t*	m_psem;

#endif
	
};

typedef VOID* (* GThreadProc)(VOID* pObject);

class GThread
{
public:
	GThread();
	~GThread();

	BOOL	Create(GThreadProc pfProc, VOID* pObject);
	BOOL	Destroy();

protected:

#if (_OS_ == _OS_WINNT_) || (_OS_ == _OS_IPHONE_)

	pthread_t	m_thread;

#endif	
};

#endif//_GTHREAD_H_
